<?php	/* gmslOpenSource 2008 */
/*
----------------------------------------------------------------------------------------
	Project name:		gmslappcore
	Section:		skin
----------------------------------------------------------------------------------------
	Script name:		skin.php
	Script location:	./gmslappcore/skin/
	Script version:		16.3
----------------------------------------------------------------------------------------
	Script info:		This is the page that will determin which skin to add
				to a page, and which page to pull onto the screen.
				There are many url options avalable on this script.
	Script dependencies:
 				~If you want a page beside the homepage, the url
				 variable "page" must be set.
 				~If you want a page beside the homepage, the url
				 variable "section" must be set.
				~"mode" url variable should be set. Can be set to either
				 "skin", "basic" or "print". If no option is set then
				 "skin" option will be taken as default.
----------------------------------------------------------------------------------------
	This script is part of the gmslappcore system which is released
	under the GNU licese.
	Copyright: (c) 2008 Andrew Cornford (groupmsl.co.uk)
	Email: projects+gmslappcore@groupmsl.co.uk
	Website: www.groupmsl.co.uk?section=cms&page=view&t=gmslappcore&f=groupmsl Open Source/gmslappcore
----------------------------------------------------------------------------------------
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------------------
*/
// Starting a new session and naming it with the name specified in the config file.
session_start();
session_name($settings['unix_id']);

// Assigning the skin mode session variable to the skin mode page variable. (If set)
if(!$_SESSION['gmslappcore_skin_mode']) include($settings['gmslappcore_location'].'skin/browser_check.php');
$page['skin_mode']=$_SESSION['gmslappcore_skin_mode'];

// Load application info.
if(($_GET['section']!='special')&&(file_exists('./apps/'.$_GET['section'].'app.php'))) include('./apps/'.$_GET['section'].'/app.php');

// Loads the desired page into the URL memory. This varaible will be overwritten if there is an error though.
$page['url']='./apps/'.$_GET['section'].'/pages/'.$_GET['page'].'.php';

// If url variable "section" is set to "special", then the system will look at system pages, not application pages.
if($_GET['section']=='special') $page['url']=$settings['gmslappcore_location'].'pages/'.$_GET['page'].'.php';

// Includes the page security file.
if(($_GET['section']=='special')&&(file_exists($settings['gmslappcore_location'].'pages/'.$_GET['page'].'_s.php'))) include($settings['gmslappcore_location'].'pages/'.$_GET['page'].'_s.php');
elseif(file_exists('./apps/'.$_GET['section'].'/pages/'.$_GET['page'].'_s.php')) include('./apps/'.$_GET['section'].'/pages/'.$_GET['page'].'_s.php');

// The security definitions file is included.
if(file_exists($page['url'])) include($settings['gmslappcore_location'].'security/security.php');

// If the error pages are stored in the appcore section then the following url is loaded into the error url variable.
if($settings['error_messages']=='appcore') $page['error_file_location']=$settings['gmslappcore_location'].'errors/';

// If the error pages are stored in the gap_user_files section then the following url is loaded into the error url variable.
else $page['error_file_location']='./gap_user_files/errors/';

// If the user is viewing website in mobile mode, but page does not support mobile mode, then the correct error is shown.
if(($app['mobile_support']=='0')&&($page['skin_mode']=='mobile')) $page['url']=$page['error_file_location'].'no_mobile.php';

// If no "page" or "section" variable on url then the homepage will be the page displayed.
elseif((!$_GET['page'])&&(!$_GET['section'])) $page['url']='./apps/home/pages/home.php';

// If only one of the variables "page" or "section" is present on the url, then the error page will be displayed.
elseif((!$_GET['page'])||(!$_GET['section'])) $page['url']=$page['error_file_location'].'url_error.php';

// If the page trying to be viewed does not exist, then an error is thrown up.
elseif(($page['url'])&&(!file_exists($page['url']))) $page['url']=$page['error_file_location'].'page_no_exist.php';

// If the page trying to be viewed is secure and the user does not have the right permissions then the security file is loaded, to screen the page from the visitor.
elseif($page['security_users']!='OK') $page['url']=$page['error_file_location'].'secure_area.php';
echo 'jdrhiuyiuay8uyirutyi'.$page['security_users'];
// Calling connector, so that system can communicate with database.
include($settings['gmslappcore_location'].'connector/connection.php');

// Retriving the skin mode variable from session variable.
$page['skin_mode']=$_SESSION['gmslappcore_skin_mode'];

// Checking to see if the user has specified a skin mode.
if(!$page['skin_mode']) $page['skin_mode']='standard';

// If the user is in normal skin mode, but has no favourite skin selected, then the default will be taken.
if(($_SESSION['gmslappcore_skin_name']=='')&&($page['skin_mode']=='standard')) $page['skin_name']=$settings['default_skin'];

// If the user is in mobile skin mode, but has no favourite skin selected, then the default will be taken.
if(($_SESSION['gmslappcore_skin_mobile_name']=='')&&($page['skin_mode']=='mobile')) $page['skin_name']=$settings['default_mobile_skin'];

// Getting the contents of the skin file to a variable.
$page['skin_complete']=file_get_contents('./gap_user_files/skins/'.$page['skin_mode'].'/'.$page['skin_name'].'/index.php');

// Splitting the variable created above, so it can be called individually later.
$page['skin_split']=explode('#GMSLAP#SKIN#',$page['skin_complete']);

// This creates the head variable for the page to display when it is called, first it calls the head part of the skin, then it adds the system css file, then deliberatly afterwards it adds the "edited" system css file (this is so the the administrator of the site can change thier copy of the system css file in the "gap_user_files" folder instead of changing the systems copy and disrupting everyone elses site that is running off the same appcore), then it adds the necessary scripts for the wysiwyg editor to work when it is called.
$page['skin_head']='?>'.$page['skin_split'][0]."
<link href=\"".$settings['gmslappcore_location']."skin/system.css\" rel=\"stylesheet\" type=\"text/css\" />"."
<link href=\"./gap_user_files/skins/".$page['skin_mode'].'/'.$page['skin_name']."/system.css\" rel=\"stylesheet\" type=\"text/css\" />
<script type=\"text/javascript\" src=\"".$settings['gmslappcore_location']."editor/v1/scripts/wysiwyg.php?gal=".$settings['gmslappcore_location']."\"></script>
<script type=\"text/javascript\" src=\"./gap_user_files/editor/v1/settings.js\"></script>";

// This is creating the variable which will be loaded in the main mage script for the page header.
$page['skin_header']='?>'.$page['skin_split'][1];

// This is creating the variable which will be loaded in the main mage script for the page footer.
$page['skin_footer']='?>'.$page['skin_split'][2];

// This will then actually call the page we want.
include($page['url']);

// This will print a very very small message at the bottom of the page displaying which version of the gmslappcore system you are using, you are welcome to remove the following line, but you might find it useful when asking for support or upgrading your system. ?>
<p class="systemminitext"><?php echo $settings['system_version']; ?></p>
